package erfgame.core.world.generator.terrain;

import erfgame.core.world.terrain.TerrainConstants;

public class BrickTerrainBlockGenerator implements TerrainBlockGenerator {
	
	private byte terrainType;
	private int x;
	private int y;
	private int z;
	private int w;
	private int h;
	private int d;
	
	public BrickTerrainBlockGenerator( byte terrainType, int x, int y, int z, int w, int h, int d ) {
		this.terrainType = terrainType;
		this.x = x;
		this.y = y;
		this.z = z;
		this.w = w;
		this.h = h;
		this.d = d;
	}

	public boolean generate(
			int bx, int by, int bz, 
			int bw, int bh, int bd,
			byte[][][] terrain) {
		int txoff = bx * bw;
		int tyoff = by * bh;
		int tzoff = bz * bd;
		for( int tx=bw; tx>0; ) {
			tx--;
			for( int ty=bh; ty>0; ) {
				ty--;
				for( int tz=bd; tz>0; ) {
					tz--;
					byte terrainToUse;
					int ax = txoff + tx;
					int ay = tyoff + ty;
					int az = tzoff + tz;
					if( ax >= x && 
						ax < x + w &&
						ay >= y &&
						ay < y + h &&
						az >= z &&
						az < z + d ) {
						terrainToUse = terrainType;
					} else {
						terrainToUse = TerrainConstants.TERRAIN_TYPE_AIR;
					}
					terrain[tx][ty][tz] = terrainToUse;
				}
			}
		}
		return true;
	}

}
